package com.huafv.flyauth.web.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huafv.flyauth.security.LoginUser;
import com.huafv.flyauth.web.admin.service.IAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

@Controller
public class BaseController {

    @Autowired
    HttpServletRequest httpServletRequest;
    @Autowired
    private IAuthentication iAuthentication;

    /**
     * 获取页面
     * @return
     */
    public Page getPage() {
        int current = ServletRequestUtils.getIntParameter(httpServletRequest, "current", 1);
        int size = ServletRequestUtils.getIntParameter(httpServletRequest, "size", 10);

        return new Page(current, size);
    }

    //获取当前用户对象
    public LoginUser getUser() {
        return (LoginUser) iAuthentication.authentication().getPrincipal();
    }

    //获取当前用户的用户名
    public String getLoginName() {
        return getUser().getUsername();
    }
}
